package com.aishua.fire.service.impl;

import java.util.List;

import com.aishua.fire.common.RequestInterfaceUtil;
import com.aishua.fire.entity.menu.AllMenuInfo;
import com.aishua.fire.mapper.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.aishua.fire.jpa.TwoLevelMenuDao;
import com.aishua.fire.jpa.entity.TwoLevelMenu;
import com.aishua.fire.mapper.MenuMapper;
import com.aishua.fire.service.MenuService;

@Service
public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenuMapper menuMapper;
	
	@Autowired
	private TwoLevelMenuDao twoLevelMenuDao;

	@Autowired
	private RequestInterfaceUtil requestUtil;

	
	@Override
	public List<LeftMenuDto> getLeftMenus() {
		String userName = requestUtil.getUserName();
		//获取一级菜单
		List<LeftMenuDto> leftMenus = menuMapper.getLeftMenus(userName);
		for(LeftMenuDto leftMenu:leftMenus) {
//			List<TwoLevelMenu> twoLevelMenus = twoLevelMenuDao.findByOneLevelId(leftMenu.getId());
			List<TwoLevelMenu> twoLevelMenus = menuMapper.getLeftTwoMenus(leftMenu.getId(),userName);
			leftMenu.setTwoLevelMenus(twoLevelMenus);
		}
		return leftMenus;
	}



	@Override
	public List<AllMenuDto> getOneLevelMenus() {
		//获得一级菜单
		return menuMapper.getOneLevelMenus();
	}



	@Override
	public List<TwoLevelMenuDto> getTwoLevelMenus(String id) {
		//获得二级菜单
	return 	menuMapper.getTwoLevelMenus(id);

	}


	@Override
	public OneLevelMenuDto getOneMenuById(long id) {
		return menuMapper.getOneMenuById(id);
	}


	@Override
	public TwoLevelMenuDto getTwoMenuById(long id) {
		return menuMapper.getTwoMenuById(id);

	}

	@Override
	public void updateTwoMenu(TwoLevelMenuDto twoLevelMenuinfo) {
		menuMapper.updateTwoMenu(twoLevelMenuinfo);

	}

	@Override
	public void updateOneMenu(AllMenuInfo oneLevelMenuinfo) {

		menuMapper.updateOneMenu(oneLevelMenuinfo);
	}


	@Override
	public void addOneMenu(AllMenuInfo oneLevelMenuinfo) {
		menuMapper.addOneMenu(oneLevelMenuinfo);

	}

	@Override
	public void addTwoMenu(TwoLevelMenuDto twoLevelMenuDto) {
		menuMapper.addTwoMenu(twoLevelMenuDto);

	}


	/**
	 * 获取二级菜单里所有的子集权限
	 */
	@Override
	public List<String> getTwoLevelMenuPerms(String twoLevelMenuId) {
		String userName = requestUtil.getUserName();
		return menuMapper.getPermsByTwoLevelIdAndUserName(userName,twoLevelMenuId);
	}



}
